//
//  BaseTableViewController.m
//  ImGuider
//
//  Created by llt on 2017/6/7.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()
@property (nonatomic, strong) UIImageView *navBGImageView;

@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.edgesForExtendedLayout = UIRectEdgeNone;
    
    // ios 11  scrollvew 的位置调整
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    self.tableView.showsVerticalScrollIndicator = NO;
    self.navBarHeight.constant = kNavigationBarHeight;
    self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, kNavigationBarHeight + 10);
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    if (self.navigationController.viewControllers.count > 1) {
        self.sideMenuController.leftViewSwipeGestureEnabled = NO;
    } else {
        self.sideMenuController.leftViewSwipeGestureEnabled = YES;
    }
}

- (void)rightBarButton:(NSString *)title color:(UIColor *)color selector:(SEL)selector {
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:selector];
    barButton.tintColor = color;
    self.navigationItem.rightBarButtonItem = barButton;
}

- (void)rightBarButtonWithImageName:(NSString *)imageName selector:(SEL)selector {
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStylePlain target:self action:selector];
    //    barButton.tintColor = HEXCOLOR(0xffffff);
    self.navigationItem.rightBarButtonItem = barButton;
}


- (void)leftBarButton:(NSString *)title  color:(UIColor *)color selector:(SEL)selector {
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:selector];
    barButton.tintColor = color;
    self.navigationItem.leftBarButtonItem = barButton;
}

- (void)leftBarButtonWithImageName:(NSString *)imageName selector:(SEL)selector {
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStylePlain target:self action:selector];
    //    barButton.tintColor = HEXCOLOR(0xffffff);
    self.navigationItem.leftBarButtonItem = barButton;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGRect barFrame = CGRectMake(0, 0, SCREEN_WIDTH, kNavigationBarHeight);
    
    barFrame.origin.y = scrollView.contentOffset.y;
    self.barImageView.frame = barFrame;
}

@end
